<template>
    <div v-for="(res, index) in singleData" class="framework">
        <div v-if="fodder.quantity === 'all'" class="sort">{{ index + 1 }}</div>
        <div class="single-box">
            <div class="link-box setting" v-if="res.type === 'link'">
                <h4>{{ res.title }}</h4>
                <div class="link-text">
                    <div class="subheading">{{ res.subheading }}</div>
                    <img :src="res.img" alt="#" />
                </div>
            </div>
            <div v-else-if="res.type === 'file'" class="file-box flex setting">
                <img class="file-img" :src="res.img" alt="#" />
                <div class="file-text">
                    <h4>{{ res.title }}</h4>
                    <div class="subheading">{{ res.subheading }}</div>
                </div>
            </div>
            <div v-else-if="res.type === 'text'" class="text-box flex setting">
                <h4>{{ res.title }}</h4>
            </div>
            <div v-else-if="res.type === 'img'" class="img-box flex">
                <img :src="res.img" alt="#" />
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import {ref, defineProps, computed} from "vue";
// 子组件
const fodder = defineProps<{
    details: Array<{
        img: string;
        title: string;
        subheading: string;
        type: string;
    }>;

    quantity: string;
}>();
const singleData = computed(() => {
    if (fodder.quantity === "sole") {
        return [fodder.details[0]];
    } else if (fodder.quantity === "all") {
        return fodder.details;
    }
    return [];
});
</script>

<style scoped lang="less">
.framework {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    height: 100%;
    align-items: center;
    width: 100%;
    overflow: hidden;
    gap: 10px;
    max-height: 120px;
    .sort {
        width: 20px;
        height: 20px;
        line-height: 20px;
        font-size: 12px;
        background: #ddd;
        border-radius: 50%;
        display: inline-block;
        text-align: center;
        flex-shrink: 0;
    }
}
.single-box {
    height: 100%;
    display: flex;
    align-items: center;
    flex-grow: 1;
}
.setting {
    flex-grow: 1;
    max-width: 260px;
    background: #fff;
    border: 1px solid #e9e9e9;
    border-radius: 5px;
    cursor: pointer;
    padding: 0 12px;
    height: 100px;
}
.link-box {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    .link-text {
        display: flex;
        justify-content: space-around;
        align-items: center;
        img {
            width: 50px;
            height: 50px;
            object-fit: cover;
            object-position: center;
            vertical-align: middle;
            border-style: none;
        }
    }
}
.file-box {
    .file-img {
        width: 56px;
        height: 56px;
        display: block;
    }
    .file-text {
        margin-left: 10px;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        height: 56px;
        overflow: hidden;
    }
}
.text-box {
    h4 {
        border: 0;
        border-radius: 0;
        padding: 0;
        font-size: 14px;
        -webkit-line-clamp: 3;
        word-break: break-all;
    }
}
.img-box {
    width: 100%;
    height: 100%;
    padding: 5px;
    img {
        width: auto;
        height: 100%;
        object-fit: cover;
        max-height: 120px;
    }
}
//共用
.subheading {
    max-width: 160px;
    max-height: 42px;
    line-height: 1.2;
    color: #888999;
    font-size: 12px;
    margin-right: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}
h4 {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    line-height: 20px;
}
</style>
